package com.hanggold.jfinal.springframework.processors;

import com.hanggold.jfinal.springframework.bean.Car;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;
import java.util.stream.Stream;

/**
 * @author <a href="mailto:sunmch@163.com">smc</a>
 * @date 2019-09-30 14:23
 * @since 1.0.0
 **/
@Component
public class MyDefaultBeanFactoryProcessor implements BeanFactoryPostProcessor {

	@Value("${username.username}")
	private String usernameusernae;

	@Resource(name = "username")
	private String username;

	@Resource(name = "systemProperties")
	private Map<String, Object> systemProperties;

	@Resource(name = "systemEnvironment")
	private Map<String, Object> systemEnvironment;

	@Autowired
	private Environment environment;

	private MyDefaultBeanFactoryProcessor() {

	}

	public MyDefaultBeanFactoryProcessor(Environment environment) {

	}

	@Override
	public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
		System.out.printf("线程: %s, 开始执行BeanFactoryPostProcessor \n", Thread.currentThread().getName());
		String[] cars = beanFactory.getBeanNamesForType(Car.class);
		Stream.of(cars).forEach(System.out::println);
	}
}
